package com.hcb.tonguetiphealth.widget.recommendhealth;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.baidu.location.LocationClient;
import com.hcb.tonguetiphealth.adapter.HealthCateListAdapter;
import com.hcb.tonguetiphealth.adapter.RecommendHealthCateListAdapter;
import com.hcb.tonguetiphealth.adapter.RecommendHealthDishListAdapter;
import com.hcb.tonguetiphealth.adapter.RecommendHealthResListAdapter;
import com.hcb.tonguetiphealth.adapter.RecommendHeathDrinksListAdapter;
import com.hcb.tonguetiphealth.global.Global;
import com.hcb.tonguetiphealth.manager.JSONManager;
import com.hcb.tonguetiphealth.manager.Location;
import com.hcb.tonguetiphealth.model.Cate;
import com.hcb.tonguetiphealth.model.Drinks;
import com.hcb.tonguetiphealth.model.HealthCate;
import com.hcb.tonguetiphealth.model.ResDish;
import com.hcb.tonguetiphealth.model.Restaurant;
import com.hcb.tonguetiphealth.model.User;
import com.hcb.tonguetiphealth.util.HttpUtils;
import com.hcb.tonguetiphealth.util.MessageWhat;
import com.hcb.tonguetiphealth.util.StringUtils;
import com.hcb.tonguetiphealth.view.DrinksBookActivity;
import com.hcb.tonguetiphealth.view.R;
import com.hcb.tonguetiphealth.widget.GeneralWidget;
import com.hcb.tonguetiphealth.widget.bookOnline.DishInfoWidget;
import com.hcb.tonguetiphealth.widget.more.ChangeCityWidget;
import com.hcb.tonguetiphealth.widget.resbook.RestaurantBookInfoWidget;

public class RecommendHealthWidget extends GeneralWidget implements OnClickListener, OnItemClickListener{
	private static final String TAG = "RecommendHealthWidget";
	private String url_wine = Global.URL + Global.servlet_recommendWines;
	private String url_res = Global.URL + Global.servlet_recommendRes;
	private String url_dish = Global.URL + Global.servlet_recommendDish;
	private String url_cate = Global.URL + Global.servlet_recommendCate;
	private String url_healthCate = Global.URL + Global.servlet_HealthCate;
	
	private final int healthCate = 0;
	private final int restaurant = 1;
	private final int cate = 2;
	private final int meal = 3;
	private final int wine = 4;
	private int currentIndex = healthCate;
	
	private Activity ctx;
	private Handler mHandler;
	private Button bt_restaurant, bt_cate, bt_meal, bt_wine, bt_healthCate;
	private LinearLayout ll_back,  llLocation;
	private ListView listView_restaurant, listView_cate, listView_meal, listView_wine;
	private View footerView_restaurant, footerView_cate, footerView_meal, footerView_wine;
	private TextView tv_footerMore_restaurant, tv_footerMore_cate, tv_footerMore_meal, tv_footerMore_wine;
	private ProgressBar pb_footerMore_restaurant, pb_footerMore_cate, pb_footerMore_meal, pb_footerMore_wine;
	private HealthCateListAdapter healthCateAdapter;
	private RecommendHeathDrinksListAdapter drinksAdapter;
	private RecommendHealthDishListAdapter dishAdapter;
	private RecommendHealthCateListAdapter cateAdapter;
	private RecommendHealthResListAdapter resAdapter;
	private List<HealthCate> healthCateList; //营养推荐
	private List<Restaurant> restaurantList; //商家
	private List<ResDish> dishList;       //美食
	private List<Cate> cateList;      //套餐
	private List<Drinks> drinksList;         //酒水
	private int mCount = 0;
	
	//add by svenke
	private String city;//城市id
	private Location location;
	private LocationClient mLocClient;
	private String lat;
	private String lng;
	protected View pb_footerMore;
	
	public RecommendHealthWidget(Context context) {
		super(context);
		ctx = (Activity)context;
		inflate(context, R.layout.recommend_health, this); 
		
		SharedPreferences preferences = ctx.getSharedPreferences(Global.CITYID, 0);
		city = preferences.getString(Global.CITYID, Global.defaultCityId);
		
		mHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				switch(msg.what) {
				case MessageWhat.BAIDU_LAOCATION_START:
					showMessageDialog(ctx, "正在确定您的位置...");
					break;
				case  MessageWhat.BAIDU_LAOCATION_SUCESS:
					mLocClient.stop();
					dismissMessageDialog();
					lat = String.valueOf( location.getLatitude() );
					lng = String.valueOf( location.getLongitude() );
					Global.lat = lat;
					Global.lng = lng;
					downRes();
					break;
				case MessageWhat.SHOW_DIALOG:
					showMessageDialog(ctx, "正在获取酒水列表...");
					break;
				case MessageWhat.DIMISS_DIALOG:

					dismissMessageDialog();
					break;
				case healthCate:
					tv_footerMore_wine.setText(R.string.app_list_footer_more_text);
					pb_footerMore_wine.setVisibility(ProgressBar.GONE);
					healthCateAdapter.notifyDataSetChanged();
					currentIndex = healthCate;
					dismissMessageDialog();
					break;
				case restaurant:
					tv_footerMore_restaurant.setText(R.string.app_list_footer_more_text);
					pb_footerMore_restaurant.setVisibility(ProgressBar.GONE);
					resAdapter.notifyDataSetChanged();
					currentIndex = restaurant;
					dismissMessageDialog();
					break;
				case cate:
					tv_footerMore_cate.setText(R.string.app_list_footer_more_text);
					pb_footerMore_cate.setVisibility(ProgressBar.GONE);
					cateAdapter.notifyDataSetChanged();
					currentIndex = cate;
					dismissMessageDialog();
					break;
				case meal:
					tv_footerMore_meal.setText(R.string.app_list_footer_more_text);
					pb_footerMore_meal.setVisibility(ProgressBar.GONE);
					dishAdapter.notifyDataSetChanged();
					currentIndex = meal;
					dismissMessageDialog();
					break;
				case wine:
					tv_footerMore_wine.setText(R.string.app_list_footer_more_text);
					pb_footerMore_wine.setVisibility(ProgressBar.GONE);
					drinksAdapter.notifyDataSetChanged();
					currentIndex = wine;
					dismissMessageDialog();
					break;
				}
			}
		};
		
		bt_healthCate = (Button)findViewById(R.id.recommend_health_health_cate_button);
		bt_restaurant = (Button)findViewById(R.id.recommend_health_restaurant_button);
		bt_cate = (Button)findViewById(R.id.recommend_health_cate_button);
		bt_meal = (Button)findViewById(R.id.recommend_health_meal_button);
		bt_wine = (Button)findViewById(R.id.recommend_health_wine_button);
		ll_back = (LinearLayout)findViewById(R.id.recommend_health_back_button);
//		ll_exchenge = (LinearLayout)findViewById(R.id.recommend_health_exchange_button);
		llLocation = (LinearLayout)findViewById(R.id.res_location_linearlayout);
		bt_healthCate.setOnClickListener(this);
		bt_restaurant.setOnClickListener(this);
		bt_cate.setOnClickListener(this);
		bt_meal.setOnClickListener(this);
		bt_wine.setOnClickListener(this);
		ll_back.setOnClickListener(this);
		llLocation.setOnClickListener(this);
		

		footerView_restaurant = LayoutInflater.from(context).inflate(R.layout.refresh_list_footer, null); 
		footerView_cate = LayoutInflater.from(context).inflate(R.layout.refresh_list_footer, null);
		footerView_meal = LayoutInflater.from(context).inflate(R.layout.refresh_list_footer, null);
		footerView_wine = LayoutInflater.from(context).inflate(R.layout.refresh_list_footer, null);
		tv_footerMore_restaurant = (TextView)footerView_restaurant.findViewById(R.id.refresh_list_footer_text);
		tv_footerMore_cate = (TextView)footerView_cate.findViewById(R.id.refresh_list_footer_text);
		tv_footerMore_meal = (TextView)footerView_meal.findViewById(R.id.refresh_list_footer_text);
		tv_footerMore_wine = (TextView)footerView_wine.findViewById(R.id.refresh_list_footer_text);
		pb_footerMore_restaurant = (ProgressBar)footerView_restaurant.findViewById(R.id.refresh_list_footer_progressbar);
		pb_footerMore_cate = (ProgressBar)footerView_cate.findViewById(R.id.refresh_list_footer_progressbar);
		pb_footerMore_meal = (ProgressBar)footerView_meal.findViewById(R.id.refresh_list_footer_progressbar);
		pb_footerMore_wine = (ProgressBar)footerView_wine.findViewById(R.id.refresh_list_footer_progressbar);
		
		listView_restaurant = (ListView)findViewById(R.id.recommend_health_restaurant_listview);
		listView_cate = (ListView)findViewById(R.id.recommend_health_cate_listview);
		listView_meal = (ListView)findViewById(R.id.recommend_health_meal_listview);
		listView_wine = (ListView)findViewById(R.id.recommend_health_wine_listview);
		
		listView_restaurant.addFooterView(footerView_restaurant);
		listView_cate.addFooterView(footerView_cate);
		listView_meal.addFooterView(footerView_meal);
		listView_wine.addFooterView(footerView_wine);
		
		listView_restaurant.setOnItemClickListener(this);
		listView_cate.setOnItemClickListener(this);
		listView_meal.setOnItemClickListener(this);
		listView_wine.setOnItemClickListener(this);
		
		initData();
	}
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		boolean isMore = arg2 == arg0.getAdapter().getCount()-1;
		
		Object object = arg0.getAdapter().getItem(arg2);
		switch(currentIndex) {
		case healthCate:
			if(isMore) {
				tv_footerMore_wine.setText(R.string.app_list_footer_getting_text);
				pb_footerMore_wine.setVisibility(ProgressBar.VISIBLE);
				downHealthCate();
			} else {
				HealthCate healthCate = (HealthCate)object;
				healthCate.setCurrent(true);
				Global.healthCateList = healthCateList;
				ctx.getIntent().putExtra("healthCate", healthCate);
				ctx.setContentView(new RecommendHealthHealthCateInfoWidget(ctx));
			}
			break;
		case restaurant:
			if(isMore) {
				tv_footerMore_restaurant.setText(R.string.app_list_footer_getting_text);
				pb_footerMore_restaurant.setVisibility(ProgressBar.VISIBLE);
				downRes();
			} else {
				Restaurant restaurant = (Restaurant)object;
				ctx.getIntent().putExtra("resId", restaurant.getId());
				Global.resList = restaurantList; 
				ctx.setContentView(new RestaurantBookInfoWidget(ctx));
				break;
			}
		case cate:
			if(isMore) {
				tv_footerMore_cate.setText(R.string.app_list_footer_getting_text);
				pb_footerMore_cate.setVisibility(ProgressBar.VISIBLE);
				downCate();
			} else {
				Cate cate = (Cate)object;
				cate.setCurrent(true);
				Global.cateList = cateList;
				ctx.getIntent().putExtra("cate", cate);
				ctx.setContentView(new RecommendHealthCateInfoWidget(ctx));
			}
			break;
		case meal:
			if(isMore) {
				tv_footerMore_meal.setText(R.string.app_list_footer_getting_text);
				pb_footerMore_meal.setVisibility(ProgressBar.VISIBLE);
				downDish();
			} else {
				ResDish meal = (ResDish)object;
				ctx.getIntent().putExtra("dishId", meal.getId());
				ctx.getIntent().putExtra("resId", meal.getResId());
				ctx.getIntent().putExtra("FromWidgetFlag", "RecommendHealthWidget");
				Global.resDishList = dishList; 
				ctx.setContentView(new DishInfoWidget(ctx));
			}
			break;
		case wine:
			/*if(isMore) {
				tv_footerMore_wine.setText(R.string.app_list_footer_getting_text);
				pb_footerMore_wine.setVisibility(ProgressBar.VISIBLE);
				downWine();
			} else {
				Drinks drinks = (Drinks)object;
				drinks.setCurrent(true);
				Global.drinksList = drinksList;
				ctx.getIntent().putExtra("drinks", drinks);
				ctx.getIntent().putExtra("from", "RecommendHealthWidget");
				ctx.setContentView(new DrinksBookDrinkInfoWidget(ctx));
			}*/
			break;
		}
	}
	public void onClick(View v) {
		switch(v.getId()) {
		case R.id.recommend_health_health_cate_button:
			currentIndex = healthCate;
			exchangeButtonBackground(R.id.recommend_health_health_cate_button);
			if(healthCateList == null || healthCateList.size() == 0) {
				downHealthCate();
			}
			break;
		case R.id.recommend_health_restaurant_button:
			currentIndex = restaurant;
			exchangeButtonBackground(R.id.recommend_health_restaurant_button);
			if (Global.lat ==null || Global.lng == null) {
				location = new Location(ctx.getApplicationContext(), mHandler);
				mLocClient = location.mLocationClient;
				mHandler.sendEmptyMessage(MessageWhat.BAIDU_LAOCATION_START);
				mLocClient.start();
			} else if(restaurantList == null || restaurantList.size() == 0) {
				lat = Global.lat;
				lng = Global.lng;
				downRes();
			}
			break;
		case R.id.recommend_health_cate_button:
			currentIndex = cate;
			exchangeButtonBackground(R.id.recommend_health_cate_button);
			if(cateList == null || cateList.size() == 0) {
				downCate();
			}
			break;
		case R.id.recommend_health_meal_button:
			currentIndex = meal;
			exchangeButtonBackground(R.id.recommend_health_meal_button);
			if(dishList == null || dishList.size() == 0) {
				downDish();
			}
			break;
		case R.id.recommend_health_wine_button:
			Intent intent = new Intent(ctx, DrinksBookActivity.class);
			ctx.startActivity(intent);
			
			/*exchangeButtonBackground(R.id.recommend_health_wine_button);
			if(drinksList == null || drinksList.size() == 0) {
				downWine();
			}*/
			break;
		case R.id.recommend_health_back_button:
			ctx.finish();
			break;
		case R.id.res_location_linearlayout:
			ctx.getIntent().putExtra("fromWidget", "RecommendHealthWidget");
			ctx.setContentView(new ChangeCityWidget(ctx));
			break;
		default:
			break;
		}
	}
	
	private void initData() {
		exchangeButtonBackground(R.id.recommend_health_health_cate_button);
		
		healthCateList = new ArrayList<HealthCate>();
		restaurantList = new ArrayList<Restaurant>();
		dishList = new ArrayList<ResDish>();
		cateList = new ArrayList<Cate>();
		drinksList = new ArrayList<Drinks>();
		
		healthCateAdapter = new HealthCateListAdapter(ctx, healthCateList);
		drinksAdapter = new RecommendHeathDrinksListAdapter(ctx, drinksList);
		dishAdapter = new RecommendHealthDishListAdapter(ctx, dishList);
		cateAdapter = new RecommendHealthCateListAdapter(ctx, cateList);
		resAdapter = new RecommendHealthResListAdapter(ctx, restaurantList);
		
		listView_restaurant.setAdapter(resAdapter);
		listView_cate.setAdapter(cateAdapter);
		listView_meal.setAdapter(dishAdapter);
		listView_wine.setAdapter(healthCateAdapter);
		//listView_wine.setAdapter(drinksAdapter);
		
		downHealthCate();
	}
	private void downWine() {
		mHandler.sendEmptyMessage(MessageWhat.SHOW_DIALOG);

		new Thread() {
			public void run() {
				mCount = drinksList.size();
				String response = null;
				try {
					List <NameValuePair> params = new ArrayList <NameValuePair>();
					params.add(new BasicNameValuePair("count", mCount +""));
					response = HttpUtils.Post(url_wine, params);
					
					if(Global.DEBUG) {
						System.out.println("downWine -----------------------------\n" + response);
					}
				} catch(Exception e) {
					Log.e(TAG, "Exception", e);
				}
				if(!StringUtils.isEmpty(response)) {
					JSONManager jManager = new JSONManager();
					Drinks drinks;
					boolean isGotJSONObject = jManager.isGotJSONObject(response);
					if(isGotJSONObject) {
						JSONArray jList = jManager.getJsonList();
						if(null == jList) {
							
						} else {
							for(int i=0; i< jList.length(); i++) {
								JSONObject jObject = getJSONObject(jList, i);
								if(null != jObject) {
									drinks = new Drinks();
									drinks.setId(getString(jObject, "itemid"));
									drinks.setName(getString(jObject, "title"));
									drinks.setImgURL(getString(jObject, "thumb"));
									drinks.setPriceTip(StringUtils.parseFloat(getString(jObject, "price")));
									drinks.setPriceMarket(StringUtils.parseFloat(getString(jObject, "marketprice")));
									drinks.setRatings(StringUtils.parseFloat(getString(jObject, "level")));
									drinks.setPopularity(StringUtils.parseInt(getString(jObject, "hits")));
									//drinks.setNum(1);
									drinksList.add(drinks);
								}
							}
							Global.drinksList = drinksList;
						}
						int count = jManager.getResult();
						String msg = jManager.getMsg();
						System.out.println("------ 得到msg: " + count + ":" + msg);
					}
				}
				mHandler.sendEmptyMessage(wine);
			}
		}.start();
	}
	private void downHealthCate() {
		new Thread() {
			public void run() {
				mCount = healthCateList.size();
				String response = null;
				try {
					List <NameValuePair> params = new ArrayList <NameValuePair>();
					params.add(new BasicNameValuePair("count", mCount +""));
					response = HttpUtils.Post(url_healthCate, params);
					
					if(Global.DEBUG) {
						System.out.println("downHealthCate -----------------------------\n" + response);
					}
				} catch(Exception e) {
					Log.e(TAG, "Exception", e);
				}
				if(!StringUtils.isEmpty(response)) {
					JSONManager jManager = new JSONManager();
					HealthCate healthCate;
					boolean isGotJSONObject = jManager.isGotJSONObject(response);
					if(isGotJSONObject) {
						JSONArray jList = jManager.getJsonList();
						if(null == jList) {
							
						} else {
							for(int i=0; i< jList.length(); i++) {
								JSONObject jObject = getJSONObject(jList, i);
								if(null != jObject) {
									healthCate = new HealthCate();
									
									healthCate.setId(getString(jObject, "id"));
									healthCate.setContent(getString(jObject, "content"));
									healthCate.setReason(getString(jObject, "reason"));
									healthCate.setSuitable(getString(jObject, "suitable"));
									healthCate.setUnsuited(getString(jObject, "unsuited"));
									healthCate.setLevel(StringUtils.parseFloat(getString(jObject, "level")));
									healthCate.setDownCount(StringUtils.parseInt(getString(jObject, "down_count")));
									healthCate.setAddTime(StringUtils.parseLong(getString(jObject, "addtime")));
									
									User user = new User();
									user.setUserId(getString(jObject, "userid"));
									user.setUserName(getString(jObject, "username"));
									user.setRealName(getString(jObject, "truename"));
									user.setImgUrl(getString(jObject, "headicon"));
									healthCate.setUser(user);

									healthCateList.add(healthCate);
								}
							}
						}
						
						int count = jManager.getResult();
						String msg = jManager.getMsg();
						System.out.println("------ 得到msg: " + count + ":" + msg);
					}
				}
				mHandler.sendEmptyMessage(healthCate);
			}
		}.start();
	}
	
	private void downRes() {
		new Thread() {
			public void run() {
				mCount = restaurantList.size();
				String response = null;
				try {
					List <NameValuePair> params = new ArrayList <NameValuePair>();
					params.add(new BasicNameValuePair("cityId", city));
					params.add(new BasicNameValuePair("lng", lng));
					params.add(new BasicNameValuePair("lat", lat));
					params.add(new BasicNameValuePair("count", mCount +""));
					response = HttpUtils.Post(url_res, params);
					
					if(Global.DEBUG) {
						System.out.println("downRes -----------------------------\n" + response);
					}
				} catch(Exception e) {
					Log.e(TAG, "Exception", e);
				}
				if(!StringUtils.isEmpty(response)) {
					JSONManager jManager = new JSONManager();
					Restaurant restaurant;
					boolean isGotJSONObject = jManager.isGotJSONObject(response);
					if(isGotJSONObject) {
						JSONArray jList = jManager.getJsonList();
						if(null == jList) {
							
						} else {
							for(int i=0; i< jList.length(); i++) {
								JSONObject jObject = getJSONObject(jList, i);
								if(null != jObject) {
									restaurant = new Restaurant();
									restaurant.setId(getString(jObject, "userid"));
									restaurant.setName(getString(jObject, "company"));
									restaurant.setLevel(StringUtils.parseFloat(getString(jObject, "level")));
									restaurant.setType(getString(jObject, "type"));
									restaurant.setDistance(getString(jObject, "distance"));
									restaurant.setImgURL(getString(jObject, "thumb"));//imgURL

									restaurantList.add(restaurant);
								}
							}
						}
						int count = jManager.getResult();
						String msg = jManager.getMsg();
						System.out.println("------ 得到msg: " + count + ":" + msg);
					}
				}
				mHandler.sendEmptyMessage(restaurant);
			}
		}.start();
	}
	private void downDish() {
		new Thread() {
			public void run() {
				mCount = dishList.size();
				String response = null;
				try {
					List <NameValuePair> params = new ArrayList <NameValuePair>();
					params.add(new BasicNameValuePair("cityId", city));
					params.add(new BasicNameValuePair("count", mCount +""));
					response = HttpUtils.Post(url_dish, params);
					
					if(Global.DEBUG) {
						System.out.println("downDish -----------------------------\n" + response);
					}
				} catch(Exception e) {
					Log.e(TAG, "Exception", e);
				}
				if(!StringUtils.isEmpty(response)) {
					JSONManager jManager = new JSONManager();
					ResDish dish;
					boolean isGotJSONObject = jManager.isGotJSONObject(response);
					if(isGotJSONObject) {
						JSONArray jList = jManager.getJsonList();
						if(null == jList) {
							
						} else {
							for(int i=0; i< jList.length(); i++) {
								JSONObject jObject = getJSONObject(jList, i);
								if(null != jObject) {
									dish = new ResDish();
									dish.setId(getString(jObject, "itemid"));
									dish.setResId(getString(jObject, "companyId"));
									dish.setResName(getString(jObject, "company"));
									dish.setTitle(getString(jObject, "title"));
									dish.setPnum(getString(jObject, "hits"));
									dish.setPrice(getString(jObject, "price"));
									dish.setDishThumb(getString(jObject, "thumb"));

									dishList.add(dish);
								}
							}
						}
						int count = jManager.getResult();
						String msg = jManager.getMsg();
						System.out.println("------ 得到msg: " + count + ":" + msg);
					}
				}
				mHandler.sendEmptyMessage(meal);
			}
		}.start();
	}
	private void downCate() {
		new Thread() {
			public void run() {
				mCount = cateList.size();
				String response = null;
				try {
					List <NameValuePair> params = new ArrayList <NameValuePair>();
					params.add(new BasicNameValuePair("cityId", city));
					params.add(new BasicNameValuePair("count", mCount +""));
					response = HttpUtils.Post(url_cate, params);
					
					if(Global.DEBUG) {
						System.out.println("downCate -----------------------------\n" + response);
					}
				} catch(Exception e) {
					Log.e(TAG, "Exception", e);
				}
				if(!StringUtils.isEmpty(response)) {
					JSONManager jManager = new JSONManager();
					Cate cate;
					boolean isGotJSONObject = jManager.isGotJSONObject(response);
					if(isGotJSONObject) {
						JSONArray jList = jManager.getJsonList();
						if(null == jList) {
							
						} else {
							for(int i=0; i< jList.length(); i++) {
								JSONObject jObject = getJSONObject(jList, i);
								if(null != jObject) {
									cate = new Cate();
									cate.setId(getString(jObject, "itemid"));
									cate.setName(getString(jObject, "title"));
									cate.setImgURL(getString(jObject, "thumb"));
									cate.setPrice(getString(jObject, "price"));
									cate.setPriceBefore(getString(jObject, "priceBefore"));
									cate.setpNum(StringUtils.parseInt(getString(jObject, "num")));

									cateList.add(cate); 
								}
							}
						}
						int count = jManager.getResult();
						String msg = jManager.getMsg();
						System.out.println("------ 得到msg: " + count + ":" + msg);
					}
				}
				mHandler.sendEmptyMessage(cate);
			}
		}.start();
	}
	private void exchangeButtonBackground(int button_id) {
		switch(button_id) {
		case R.id.recommend_health_health_cate_button:
			bt_healthCate.setBackgroundResource(R.drawable.label_bg_active);
			bt_restaurant.setBackgroundResource(R.drawable.xml_button_label);
			bt_cate.setBackgroundResource(R.drawable.xml_button_label);
			bt_meal.setBackgroundResource(R.drawable.xml_button_label);
			bt_wine.setBackgroundResource(R.drawable.xml_button_label);
			listView_restaurant.setVisibility(ListView.GONE);
			listView_cate.setVisibility(ListView.GONE);
			listView_meal.setVisibility(ListView.GONE);
			listView_wine.setVisibility(ListView.VISIBLE);
			break;
		case R.id.recommend_health_restaurant_button:
			bt_healthCate.setBackgroundResource(R.drawable.xml_button_label);
			bt_restaurant.setBackgroundResource(R.drawable.label_bg_active);
			bt_cate.setBackgroundResource(R.drawable.xml_button_label);
			bt_meal.setBackgroundResource(R.drawable.xml_button_label);
			bt_wine.setBackgroundResource(R.drawable.xml_button_label);
			listView_restaurant.setVisibility(ListView.VISIBLE);
			listView_cate.setVisibility(ListView.GONE);
			listView_meal.setVisibility(ListView.GONE);
			listView_wine.setVisibility(ListView.GONE);
			break;
		case R.id.recommend_health_cate_button:
			bt_healthCate.setBackgroundResource(R.drawable.xml_button_label);
			bt_restaurant.setBackgroundResource(R.drawable.xml_button_label);
			bt_cate.setBackgroundResource(R.drawable.label_bg_active);
			bt_meal.setBackgroundResource(R.drawable.xml_button_label);
			bt_wine.setBackgroundResource(R.drawable.xml_button_label);
			listView_restaurant.setVisibility(ListView.GONE);
			listView_cate.setVisibility(ListView.VISIBLE);
			listView_meal.setVisibility(ListView.GONE);
			listView_wine.setVisibility(ListView.GONE);
			break;
		case R.id.recommend_health_meal_button:
			bt_healthCate.setBackgroundResource(R.drawable.xml_button_label);
			bt_restaurant.setBackgroundResource(R.drawable.xml_button_label);
			bt_cate.setBackgroundResource(R.drawable.xml_button_label);
			bt_meal.setBackgroundResource(R.drawable.label_bg_active);
			bt_wine.setBackgroundResource(R.drawable.xml_button_label);
			listView_restaurant.setVisibility(ListView.GONE);
			listView_cate.setVisibility(ListView.GONE);
			listView_meal.setVisibility(ListView.VISIBLE);
			listView_wine.setVisibility(ListView.GONE);
			break;
		case R.id.recommend_health_wine_button:
			bt_restaurant.setBackgroundResource(R.drawable.xml_button_label);
			bt_cate.setBackgroundResource(R.drawable.xml_button_label);
			bt_meal.setBackgroundResource(R.drawable.xml_button_label);
			bt_wine.setBackgroundResource(R.drawable.label_bg_active);
			listView_restaurant.setVisibility(ListView.GONE);
			listView_cate.setVisibility(ListView.GONE);
			listView_meal.setVisibility(ListView.GONE);
			listView_wine.setVisibility(ListView.VISIBLE);
			break;
		default:
			break;
		}
	}
	@Override
	public void notifyAdapter() {
		
	}
}
